package com.atguigu.flink.chapter10.sql;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class SQLDemo {
    public static void main(String[] args) {
        Configuration conf = new Configuration();
        conf.setInteger("rest.port", 2000);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(conf);
        env.setParallelism(1);

        StreamTableEnvironment tEnv = StreamTableEnvironment.create(env);

        /*tEnv.executeSql("create database abc");
        tEnv.executeSql("show databases").print();
        tEnv.executeSql("show current database").print();
        tEnv.executeSql("use abc");
        tEnv.executeSql("show current database").print();*/

        tEnv.executeSql("create table sensor(" +
                " id string, " +
                " ts bigint, " +
                " vc int," +
//                            "`record_time` TIMESTAMP_LTZ(3) METADATA FROM 'timestamp' " +
//                            "`timestamp` TIMESTAMP_LTZ(3) METADATA,  " +
                "`topic` string METADATA  " +
                ")with(" +
                "  'connector' = 'kafka', " +
                "  'topic' = 's1', " +
                "  'properties.bootstrap.servers' = 'hadoop162:9092', " +
                "  'properties.group.id' = 'atguigu', " +
                "  'scan.startup.mode' = 'latest-offset', " +
                "  'format' = 'csv' " +
                ")");

        tEnv.sqlQuery("select * from sensor").execute().print();

    }
}

